package com.jingdianjichi.subject.application.controller;

import com.alibaba.fastjson.JSON;
import com.jingdianjichi.subject.common.entity.PageResult;
import com.jingdianjichi.subject.infra.basic.ES.自定义ES_鸡翅.entity.SubjectInfoES;
import com.jingdianjichi.subject.infra.basic.ES.自定义ES_鸡翅.service.SubjectESService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/*
  测试ES的controller
 */
@RestController
@RequestMapping("/test/es")
@Slf4j
public class TestESController {

    /*
     SpringDataES的测试

        @Resource
        private SubjectESService subjectESService;


        @GetMapping("/createIndex")
        public void createIndex(){
            subjectESService.CreateIndex();
        }

        @GetMapping("/addDocs")
        public void addDocs(){
            subjectESService.addDoc();
        }

        @GetMapping("/find")
        public void find(){
            subjectESService.find();
        }

        @GetMapping("/search")
        public void search(){
            subjectESService.search();
        }
    */

    /*
        自定义ES的测试
     */
    @Resource
    private SubjectESService esService;

    //测试高亮查询
    @PostMapping("/querySubjectByKeyWord")
    public void querySubjectByKeyWord(){
        SubjectInfoES subjectInfoEs=new SubjectInfoES();
        subjectInfoEs.setKeyWord("redis");
        PageResult<SubjectInfoES> pageResult = esService.querySubjectList(subjectInfoEs);


        //高版本,垃圾垃圾
        log.info("querySubjectByKeyWord:{}",JSON.toJSONString(pageResult));
    }

}

